<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="生产部门">
        <el-select v-model="formInline.deId" size="mini">
          <el-option label="经理办公室" value="3"></el-option>
          <el-option label="特务部" value="5"></el-option>
          <el-option label="研发部" value="6"></el-option>
          <el-option label="结构部" value="8"></el-option>
          <el-option label="西安分公司" value="12"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="年">
        <el-select v-model="formInline.nian">
          <el-option label="2017" value="2017"></el-option>
          <el-option label="2018" value="2018"></el-option>
          <el-option label="2019" value="2019"></el-option>
          <el-option label="2020" value="2020"></el-option>
          <el-option label="2021" value="2021"></el-option>
          <el-option label="2022" value="2022"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="月">
        <el-select v-model="formInline.yue">
          <el-option label="1" value="1"></el-option>
          <el-option label="2" value="2"></el-option>
          <el-option label="3" value="3"></el-option>
          <el-option label="4" value="4"></el-option>
          <el-option label="5" value="5"></el-option>
          <el-option label="6" value="6"></el-option>
          <el-option label="7" value="7"></el-option>
          <el-option label="8" value="8"></el-option>
          <el-option label="9" value="9"></el-option>
          <el-option label="10" value="10"></el-option>
          <el-option label="11" value="11"></el-option>
          <el-option label="12" value="12"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="show">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" @click="handleDel">删除</el-button>
      </el-form-item>
    </el-form>
    <el-table ref="multipleTable" :data="tableData" style="width: 100%">
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column label="序号" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.bmhd_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" sortable width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.bmhd_start_date }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请人" sortable width="180">
        <template>
          <span style="margin-left: 10px">管理员</span>
        </template>
      </el-table-column>
      <el-table-column label="所属部门" sortable width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.deptName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活动事由" sortable width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.bmhd_reason }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开始时间" sortable width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.bmhd_start_date }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" sortable width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.bmhd_end_date }}</span>
        </template>
      </el-table-column>
      <el-table-column label="考勤统计（小时）" sortable width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.bmhd_kqtj }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" sortable width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.bmhd_note }}</span>
        </template>
      </el-table-column>
      <el-table-column label="部门经理审批" sortable width="180">
        <template>
          <span style="margin-left: 10px">张翠珍</span>
        </template>
      </el-table-column>
      <el-table-column label="总经理审批" sortable width="180">
        <template>
          <span style="margin-left: 10px"></span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row.bmhd_id)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="show"
      @current-change="show"
      :current-page.sync="psgeIndex"
      :page-sizes="[3, 6, 9, 12]"
      :page-size.sync="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <el-dialog title="编辑" :visible.sync="dialogUpdateVisible">
      <el-form :model="bform">
        <el-form-item label="活动事由">
          <el-radio-group v-model="bform.bmhd_reason">
            <el-radio :label="'组织活动'">组织活动</el-radio>
            <el-radio :label="'聚餐'">聚餐</el-radio>
            <el-radio :label="'其他'">其他</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="申请时间">
          <el-input v-model="bform.bmhd_start_date"></el-input>
          <span> 至 </span>
          <el-input v-model="bform.bmhd_end_date"></el-input>
        </el-form-item>
        <el-form-item label="考勤统计">
          <el-input v-model="bform.bmhd_kqtj"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="bform.bmhd_note"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogUpdateVisible = false">取消</el-button>
        <el-button type="primary" @click="UpdateCun">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      psgeIndex: 1,
      pageSize: 3,
      total: 0,
      formInline: {
        deId: 0,
        nian: "",
        yue: "",
      },
      bform: {
        bmhd_id: 0,
        bmhd_reason:"",
        bmhd_start_date: "2022-01-05T02:58:47.117Z",
        bmhd_end_date: "2022-01-05T02:58:47.117Z",
        bmhd_kqtj:0.0,
        bmhd_note: "",
      },
      dialogUpdateVisible: false,
    };
  },
  created() {
    this.show();
  },
  methods: {
    show() {
      this.$axios
        .get(
          "http://localhost:20932/api/SystemManager/DepartmentActivityApply/GetDepartmentActivityApplyList?deId=" +
            this.formInline.deId +
            "&nian=" +
            this.formInline.nian +
            "&yue=" +
            this.formInline.yue +
            "&pageIndex=" +
            this.psgeIndex +
            "&pageSize=" +
            this.pageSize
        )
        .then((r) => {
          if (r.status == 200) {
            this.tableData = r.data.list;
            this.total = r.data.total;
          }
        });
    },
    handleEdit(id) {
      this.dialogUpdateVisible = true;
      this.$axios
        .get(
          "http://localhost:20932/api/SystemManager/DepartmentActivityApply/GetDepartmentActivityApplyFan?id=" +
            id
        )
        .then((r) => {
          if (r.status == 200) {
            this.bform = r.data;
          }
        });
    },
    UpdateCun() {
      this.$axios
        .post(
          "http://localhost:20932/api/SystemManager/DepartmentActivityApply/GetDepartmentActivityApplyUpdate",
          this.bform
        )
        .then((r) => {
          if ((r.status == 200) & r.data) {
            this.$message("修改成功");
            this.dialogUpdateVisible = false;
            this.show();
          }
        });
    },
    handleDel() {
      var list = this.$refs["multipleTable"].selection;
      var ids = [];
      if (list.length === 0) {
        this.$message("至少选中一个");
        return false;
      }
      list.forEach((r) => {
        ids.push(r.bmhd_id);
      });
      if (!confirm("确定删除吗？")) {
        return false;
      }
      this.$axios
        .post(
          "http://localhost:20932/api/SystemManager/DepartmentActivityApply/GetDepartmentActivityApplyDel?ids=" +
            ids
        )
        .then((r) => {
          if ((r.status == 200) & r.data) {
            this.$message("删除成功");
            this.show();
          }
        });
    },
  },
};
</script>